#include <iostream>
#include <stack>
#include <map>
using namespace std;


struct node{
	int stop,next;
};


int main(){
	long long n,m,ans=0;
	map<long long,node> map;
	stack<long long> stack;
	cin>>n;
	m = n;
	long long learn[n]={0},time[n];
	for(int i=0;i<n;i++){
		long long need_num;
		cin>>time[i]>>need_num;
		node l;
		l.next = m;
		map[i] = l;
		for(int j=0;j<need_num;j++){
			long long need;
			cin>>need;
			l.stop = need-1;
			l.next = m+1;
			map[m] = l;
			m++;
		}
		if(need_num == 0)
			map[i].next = -1;
		else
			map[m-1].next = -1;
	}
	stack.push(n-1);
	while(!stack.empty()){
		if(learn[stack.top()] == 1){
			stack.pop();
			continue;
		}
		node nod;
		bool canl=true;
		nod = map[stack.top()];
		while(nod.next != -1){
			nod = map[nod.next];
			if(learn[nod.stop] == 0){
				stack.push(nod.stop);
				canl = false;
			}
		}
		if(canl){
			ans += time[stack.top()];
			learn[stack.top()] = 1;
			stack.pop();
		}
	}
	cout<<ans;
	return 0;
}
